<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8" />
		<meta name="viewport" content="width=device-width, initial-scale=1">
		<link rel="stylesheet" href="../../res/layui/css/layui.css" media="all">
		<link rel="stylesheet" href="../../res/css/common/font-awesome.min.css" media="all">
		<link rel="stylesheet" href="../../res/layui-config/css/app.css" media="all">
		<title>制造计划管理</title>
	</head>
	<body>
		<div class="kit-table">
		    <form class="layui-form" lay-filter="kit-search-form">
						<!-- 左上角的两个按钮 -->
		        <div class="kit-table-header">
		             
		            <div class="kit-search-inputs">
		                <div class="kit-search-keyword">
		                    <input type="text" class="layui-input" name="drugName" placeholder="请输入药品名称." />
		                    <button lay-submit lay-filter="search"><i class="layui-icon">&#xe615;</i></button>
		                </div>
		             
		            </div>
		        </div>
		    </form>
				
				<!-- 操作按钮 -->
		    <div class="kit-table-body">
		        <table id="demo" lay-filter="demo"></table>
		        <script type="text/html" id="barDemo">
		            <a class="layui-btn layui-btn-xs" lay-event="detail">查看</a>
		            <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
		            <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
		        </script>
		    </div>
		</div>
		
		<!-- 修改页面 -->
		<script type="text/html" id="edit-tpl">
		    <div style="margin:10px">
		        <form class="layui-form" action="" lay-filter="form-edit">
		            <input type="hidden" name="id" value="{{d.user.id}}" />
		            <div class="layui-form-item">
		                <label class="layui-form-label">用户名</label>
		                <div class="layui-input-block">
		                    <input type="text" name="username" required lay-verify="required" value="{{d.user.username}}" placeholder="请输入标题" autocomplete="off" class="layui-input">
		                </div>
		            </div>
		            <div class="layui-form-item">
		                <label class="layui-form-label">密码框</label>
		                <div class="layui-input-inline">
		                    <input type="password" name="password" required lay-verify="required" placeholder="请输入密码" autocomplete="off" class="layui-input">
		                </div>
		                <div class="layui-form-mid layui-word-aux">辅助文字</div>
		            </div>
		            <div class="layui-form-item">
		                <label class="layui-form-label">单选框</label>
		                <div class="layui-input-block">
		                    {{# var woman = d.user.sex === 0?'checked':'';}} {{# var man = d.user.sex === 1?'checked':'';}}
		                    <input type="radio" name="sex" value="男" title="男" {{man}} />
		                    <input type="radio" name="sex" value="女" title="女" {{woman}} />
		                </div>
		            </div>
		            <div class="layui-form-item">
		                <label class="layui-form-label">城市</label>
		                <div class="layui-input-block">
		                    <select name="city" lay-verify="required">
		                      <option value=""></option>
		                      {{# layui.each(d.citys,function(index,item){ }}                      
		                      {{# if(item.id===d.user.city){}}
		                      <option value="{{item.id}}" selected>{{item.name}}</option>
		                      {{#}else{}}
		                      <option value="{{item.id}}">{{item.name}}</option>
		                      {{#};}}
		                      {{# }); }}
		                    </select>
		                </div>
		            </div>
		            <div class="layui-form-item">
		                <label class="layui-form-label">积分</label>
		                <div class="layui-input-block">
		                    <input type="number" name="experience" required lay-verify="required" value="{{d.user.experience}}" placeholder="请输入积分" autocomplete="off" class="layui-input">
		                </div>
		            </div>
		            <div class="layui-form-item">
		                <label class="layui-form-label">评分</label>
		                <div class="layui-input-block">
		                    <input type="number" name="score" required lay-verify="required" value="{{d.user.score}}" placeholder="请输入评分" autocomplete="off" class="layui-input">
		                </div>
		            </div>
		            <div class="layui-form-item">
		                <label class="layui-form-label">财富</label>
		                <div class="layui-input-block">
		                    <input type="number" name="wealth" required lay-verify="required" value="{{d.user.wealth}}" placeholder="请输入财富" autocomplete="off" class="layui-input">
		                </div>
		            </div>
		            <div class="layui-form-item">
		                <label class="layui-form-label">职业</label>
		                <div class="layui-input-block">
		                    <select name="classify" lay-verify="required">
		                        <option value=""></option>                        
		                      {{# layui.each(d.classifies,function(index,item){ }}
		                      {{# if(item.id===d.user.classify){}}
		                      <option value="{{item.id}}" selected>{{item.name}}</option>
		                      {{#}else{}}
		                      <option value="{{item.id}}">{{item.name}}</option>
		                      {{#};}}
		                      {{# }); }}
		                    </select>
		                </div>
		            </div>
		            <div class="layui-form-item layui-form-text">
		                <label class="layui-form-label">签名</label>
		                <div class="layui-input-block">
		                    <textarea name="sign" placeholder="请输入个性签名" class="layui-textarea">{{d.user.sign}}</textarea>
		                </div>
		            </div>
		            <div class="layui-form-item" style="display:none;">
		                <div class="layui-input-block">
		                    <button class="layui-btn" lay-submit lay-filter="formEdit">立即提交</button>
		                    <button type="reset" class="layui-btn layui-btn-primary">重置</button>
		                </div>
		            </div>
		        </form>
		    </div>
		</script>
		
		<!-- 显示表格 -->
		<script src="../../res/layui/layui.js"></script>
		<script src="../../res/js/common/parameter.js"></script>
		<script>
		    layui.use(['table'], function() {
		    	var diId = getParameter("id");
		        var table = layui.table,
		            $ = layui.jquery,
		            layer = layui.layer,
		            form = layui.form,
		            laytpl = layui.laytpl;
		        var tableIns = table.render({
		            elem: '#demo',
		            height: 'full', //容器高度
		            url: '../../drugInvDetail/findById.action?diId='+diId,
		            page: true,
		            id: 'demo',
		            cols: [
		                [{
		                    checkbox: true,
		                    fixed: true
		                }, {
		                    field: 'drugName',
		                    title: '药品名称',
		                    width: 190
		                }, {
		                    field: 'diAmount',
		                    title: '药品数量',
		                    width: 150
		                }, {
		                    field: 'remarksName',
		                    title: '出入库',
		                    width: 150
		                }, {
		                    field: 'drugPrice',
		                    title: '药品单价',
		                    width: 160
		                } ,{
		                    field: 'timeName',
		                    title: '出库入库时间',
		                    width: 160
		                }
		                ]
		            ],
		            done: function(res, curr, count) {
		                //如果是异步请求数据方式，res即为你接口返回的信息。
		                //如果是直接赋值的方式，res即为：{data: [], count: 99} data为当前页数据、count为数据总长度
		                // console.log(res);
		                // //得到当前页码
		                // console.log(curr);
		                // //得到数据总量
		                // console.log(count);
		            },
		            loading: true,
		            //method: 'post'
		        });
						//城市及角色
		        var staticData = {
		            citys: [{
		                id: 0,
		                name: '北京'
		            }, {
		                id: 1,
		                name: '广州'
		            }, {
		                id: 2,
		                name: '深圳'
		            }, {
		                id: 3,
		                name: '杭州'
		            }],
		            classifies: [{
		                id: 0,
		                name: '词人'
		            }, {
		                id: 1,
		                name: '诗人'
		            }, {
		                id: 2,
		                name: '作家'
		            }, {
		                id: 3,
		                name: '酱油'
		            }]
		        };
		        //监听搜索表单提交
		        form.on('submit(search)', function(data) {
		            //带条件查询
		            tableIns.reload({
		                where: data.field
		            });
		            return false;
		        });
		        //监听工具条
		        table.on('tool(demo)', function(obj) { //注：tool是工具条事件名，test是table原始容器的属性 lay-filter="对应的值"
		            var data = obj.data; //获得当前行数据
		            var layEvent = obj.event; //获得 lay-event 对应的值
		            var tr = obj.tr; //获得当前行 tr 的DOM对象
		
		            if (layEvent === 'detail') { //查看
		                console.log(table.checkStatus('demo'));
		            } else if (layEvent === 'del') { //删除
		                layer.confirm('真的删除行么', function(index) {
		                    obj.del(); //删除对应行（tr）的DOM结构
		                    layer.close(index);
		                    //向服务端发送删除指令
		                });
		            } else if (layEvent === 'edit') { //编辑
		                var d = {
		                    user: data,
		                    citys: staticData.citys,
		                    classifies: staticData.classifies
		                };
		                laytpl($('#edit-tpl').html()).render(d, function(html) {
		                    layer.open({
		                        type: 1,
		                        title: '表单',
		                        content: html,
		                        area: ['800px', '450px'],
		                        btn: ['提交', '重置', '取消'],
		                        yes: function(index, layero) {
		                            editIndex = index;
		                            $('form[lay-filter="form-edit"]').find('button[lay-submit]').click();
		                        },
		                        btn2: function(index, layero) {
		                            $('form[lay-filter="form-edit"]').find('button[type="reset"]').click();
		                            return false;
		                        },
		                        success: function() {
		                            form.render(null, 'form-edit');
		                        }
		                    });
		                });
		                //同步更新缓存对应的值
		                // obj.update({
		                //     username: '123',
		                //     title: 'xxx'
		                // });
		            }
		        });
		        form.render(null, 'kit-search-form');
		        $('#kit-search-more').on('click', function() {
		            $('.kit-search-mored').toggle();
		        });
		        var editIndex;
		        form.on('submit(formEdit)', function(data) {
		            layer.msg('formEdit');
		            editIndex && layer.close(editIndex); //关闭弹出层
		            return false;
		        });
		        $('.kit-search-btns').children('a').off('click').on('click', function() {
		            var $that = $(this),
		                action = $that.data('action');
		            switch (action) {
		                case 'add':
		                    var d = {
		                        user: {
		                            sign: '你哈',
		                            city: '',
		                            classify: '',
		                            experience: '',
		                            id: 0,
		                            logins: '',
		                            score: '',
		                            sex: 1,
		                            sign: '',
		                            username: '',
		                            wealth: ''
		                        },
		                        citys: staticData.citys,
		                        classifies: staticData.classifies
		                    };
		                    //渲染
		                    laytpl($('#edit-tpl').html()).render(d,
		                        function(html) {
		                            layer.open({
		                                type: 1,
		                                title: '表单',
		                                content: html,
		                                area: ['800px', '450px'],
		                                btn: ['提交', '重置', '取消'],
		                                yes: function(index, layero) {
		                                    editIndex = index;
		                                    $('form[lay-filter="form-edit"]').find('button[lay-submit]').click();
		                                },
		                                btn2: function(index, layero) {
		                                    $('form[lay-filter="form-edit"]').find('button[type="reset"]').click();
		                                    return false;
		                                },
		                                success: function() {
		                                    form.render(null, 'form-edit');
		                                }
		                            });
		                        });
		                    break;
		                case 'del-bulk':
		                    var d = table.checkStatus('demo');
		                    if (d.data.length === 0) {
		                        layer.msg('请选择要删除的数据');
		                        return;
		                    }
		                    var data = d.data,
		                        names = [],
		                        ids = [];
		                    layui.each(data, function(index, item) {
		                        console.log(item);
		                        names.push(item.username);
		                        ids.push(item.id);
		                    });
		                    layer.msg(names.join(','));
		                    console.log(ids.join(','));
		                    break;
		            }
		        });
		    });
		   
		</script>
		<script type="text/javascript"></script>
	</body>
</html>
